Thread: Linux raw socket programming

  1. #16
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I learned a lot from this site:
    Beej's Guide to Network Programming
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  2. #17
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by jeffcobb View Post
    I learned a lot from this site:
    Beej's Guide to Network Programming
    Except Beej's guide has nothing to do with RAW sockets. And if the guy who asked hasn't found the answer in the last year since he posted, then I think it's too little too late
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #18
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    workaround

    Here is the workaround how to get source ip. (It is adopted part from iputils)

    Code:
    int probe_fd = socket(AF_INET,SOCK_DGRAM,0);
    struct sockaddr_in dst;
    dst.sin_family = AF_INET;
    connect(probe_fd, (struct sockaddr*)&dst, sizeof(dst));
    socklen_t alen = sizeof(dst);
    getsockname(probe_fd, (struct sockaddr*)&dst, &alen);
    close(probe_fd);
    printf("Source: %s\n",inet_ntoa(dst.sin_addr));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Raw socket
    By like_no_other in forum Networking/Device Communication
    Replies: 4
    Last Post: 03-28-2009, 02:05 PM
  2. socket programming in c or c++ in linux...
    By pk20 in forum Linux Programming
    Replies: 5
    Last Post: 02-12-2009, 01:54 AM
  3. Raw serial control in Linux
    By crepincdotcom in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-12-2008, 12:17 PM
  4. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 06:57 AM
  5. socket programming in linux
    By crazeinc in forum C Programming
    Replies: 1
    Last Post: 05-27-2005, 07:40 PM