hi heres my sample code
why am i getting a "bad address" error with ioctl?Code:#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <sys/ioctl.h> int main (void) { int sockfd; int io; char buffer[1024]; sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd < 0){ perror("socket"); exit(1); } io = ioctl(sockfd, SIOCGIFHWADDR, (char *)buffer); if(io < 0){ perror("ioctl"); exit(1); } printf("fetched HW address with ioctl on sockfd.\n"); printf("HW address of interface is: %s\n", buffer); exit(0); }
i found the constant used with the ioctl in bits/ioctls.h.
sockfd is obviously a socket but why isnt it working?
thanks



LinkBack URL
About LinkBacks


