Linux raw socket programming

This is a discussion on Linux raw socket programming within the Networking/Device Communication forums, part of the General Programming Boards category; I learned a lot from this site: Beej's Guide to Network 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,261
    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));

Page 2 of 2 FirstFirst 12
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, 03: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, 01:17 PM
  4. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 07:57 AM
  5. socket programming in linux
    By crazeinc in forum C Programming
    Replies: 1
    Last Post: 05-27-2005, 08:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21