Sun에서 mac address 얻어오기...

eminency의 이미지

아래와 같이 작성해서 돌려봤는데(리눅스에서 쓰던 소스를 ioctl의 request부분을 비롯 약간 고친 것입니다) 실행하면 두번째 ioctl에서(SIOCGENADDR) 에러가 납니다.
에러 내용은 No such file or directory인데요. 앞의 ioctl이 제대로 수행되었으므로 socket 실행이나 fd에 문제가 없어야 정상인데 도무지 이유를 알 수가 없습니다.

서버는 SunOS blade2 5.9 에서 돌려보았습니다.
첫번째 ioctl에서 lo0이나 hme0 등의 인터페이스 명은 제대로 받아옵니다.

조언을 부탁드립니다.

#include	<stdio.h>
#include	<unistd.h>
#include 	<string.h>
#include 	<stropts.h>
 
 
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
 
#include <arpa/inet.h>
 
#define MAX_NIC 10
 
void
get_macaddr(void)
{
    int i, j, fd;
    int numif;
    static char ip[INET_ADDRSTRLEN];
 
    struct ifconf ifc;
    struct ifreq *ifrp;
    struct in_addr addr;
    struct ifreq ifr[MAX_NIC];
 
    memset (ifr, 0x00, sizeof(struct ifreq)*MAX_NIC);
    ifc.ifc_len = sizeof(ifr);
    ifc.ifc_buf = (char *)ifr;
 
    if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
    {
        perror("socket");
        return ;
    }
    if(ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
        perror("get interface");
        return ;
    }
 
    numif = ifc.ifc_len / sizeof(struct ifreq);
 
    for(i = 0; i < numif; i++) 
    {
        if (strcmp(ifr[i].ifr_name, "lo0") == 0)
            continue;
 
        if (ioctl (fd, SIOCGENADDR, &ifr[i]) == -1)
        {
            perror("get hwaddr");
            return ;
        }
 
        printf("%s\n", ether_ntoa(ifr.ifr_enaddr));
    }
 
    close(fd);
 
    return ;
}
 
int
main()
{
    get_macaddr();
}
park7275의 이미지

아래 링크를 참조하세요~

http://access1.sun.com/cgi-bin/rinfo2html?328105.faq

이렇게 찾아야 하나 봅니다.

Sun에서는 ioctl(SIOCGENADDR)로는 errno(2)인 No such file or directory 가 나오나 보네요~

[KILL] 죽을각오로.........

[KILL] 죽을각오로.........

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.