Beej.us

This is a discussion on Beej.us within the Networking/Device Communication forums, part of the General Programming Boards category; Hey guys, I'm running in almost the same problem as this guy : http://cboard.cprogramming.com/netwo...orking-me.html Thing is, when running talker, I ...

  1. #1
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187

    Beej.us

    Hey guys,
    I'm running in almost the same problem as this guy :

    Sockets tutorial, datagram sockets example not working for me

    Thing is, when running talker, I do write it like this :

    Code:
    ./talker hostname ola
    where my hostname is the hostname of my partner.

    We're both running MacBookPro's and I get the following error :

    Code:
    getaddrinfo: nodename nor servname provided, or not known
    Any idea what might be happening ?

    Works fine for me running both on two terminals on my PC

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    It sounds like your computer doesn't know how to find your partner's computer. Are you using a host name or an IP address? If host name, how does your computer know what IP address it maps to? /etc/hosts? Is it in some DNS somewhere?

  3. #3
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by anduril462 View Post
    It sounds like your computer doesn't know how to find your partner's computer. Are you using a host name or an IP address? If host name, how does your computer know what IP address it maps to? /etc/hosts? Is it in some DNS somewhere?
    Hi anduril, thanks for replying.
    I'm using a host name but yeah, I need the IP, wasn't figuring that out.
    We're on the same internet though, and we're in a room where everyone has that IP, is that a problem ?

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    The room you're in and the subnet you're on are not necessarily related in any way. There could be several subnets in one physical room, or one subnet spanning several rooms or even buildings. So everybody in the room having the same IP is not necessarily a problem, it's the subnet that matters. If everybody on the subnet you're on has the same IP, though, or even just two people, that is a problem. But I can only imagine that happening if
    1. People have their computers set to the same static IP address (unlikely)
    2. People have the same MAC address, so the DHCP server is confused and handing out the same IP to different computers (extremely unlikely)

    So I doubt everybody has the same IP. If they really do, how did you verify this? If you can talk reliably to your partner's computer via IP address there's a really good chance nobody else has that address.

  5. #5
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    The IP I'm talking about is the following :

    What Is My IP Address | Shows Your IP Address

    I guess what you're telling me to do is instead of doing ./talker "Internet IP" you're telling me to do ./talker "Partner MAC Address".

    Am I right ?
    Thanks for the time spent on this anduril!

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    > I guess what you're telling me to do is instead of doing ./talker "Internet IP" you're telling me to do ./talker "Partner MAC Address".
    No. I recommend you read up on IP and MAC addresses to learn the difference. You want to use their "non-internet" IP address. See below and Google "private network" for more info. Here's a place to start: http://en.wikipedia.org/wiki/Private_network.

    > What Is My IP Address | Shows Your IP Address
    That isn't the IP of the computer you're on. That's the IP "to the outside world", for the whole internet.

    Presumably you're at school or in somebody's house, on a private network. There is a router/gateway that connects you to the outside world, so you can get to Google, C Board, etc. You need a public IP address for that. But there aren't enough for everybody to have one, so the router/gateway allows several people inside on the private network to talk to people in the "outside world" with just one IP address. Think of a large office building that has one physical mailing address where all the mail from the post office is delivered, but there is somebody in the mail room that sorts the mail and delivers it to the hundreds of people working there. That mail room sorter is a bit like the gateway. If you want to send intra-office mail, you only need the person's name, or room number. You don't need to address a letter to the building you're currently in, put a stamp on it and take it to the post office. You just drop it in the mail slot and the person in the mail room will deliver it directly.

    How to find the IP of your computer depends on what OS you're using. Look for where you change system/network settings (perhaps the same place, or near where you set up a new wireless network, for example). You'll probably see something like 192.168.x.x or 10.x.x.x. Those are groups of IP adress reserved for private networks, they never refer to stuff that is "directly connected" to the internet.

  7. #7
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by anduril462 View Post
    > I guess what you're telling me to do is instead of doing ./talker "Internet IP" you're telling me to do ./talker "Partner MAC Address".
    No. I recommend you read up on IP and MAC addresses to learn the difference. You want to use their "non-internet" IP address. See below and Google "private network" for more info. Here's a place to start: Private network - Wikipedia, the free encyclopedia.

    > What Is My IP Address | Shows Your IP Address
    That isn't the IP of the computer you're on. That's the IP "to the outside world", for the whole internet.

    Presumably you're at school or in somebody's house, on a private network. There is a router/gateway that connects you to the outside world, so you can get to Google, C Board, etc. You need a public IP address for that. But there aren't enough for everybody to have one, so the router/gateway allows several people inside on the private network to talk to people in the "outside world" with just one IP address. Think of a large office building that has one physical mailing address where all the mail from the post office is delivered, but there is somebody in the mail room that sorts the mail and delivers it to the hundreds of people working there. That mail room sorter is a bit like the gateway. If you want to send intra-office mail, you only need the person's name, or room number. You don't need to address a letter to the building you're currently in, put a stamp on it and take it to the post office. You just drop it in the mail slot and the person in the mail room will deliver it directly.

    How to find the IP of your computer depends on what OS you're using. Look for where you change system/network settings (perhaps the same place, or near where you set up a new wireless network, for example). You'll probably see something like 192.168.x.x or 10.x.x.x. Those are groups of IP adress reserved for private networks, they never refer to stuff that is "directly connected" to the internet.
    Alright, thanks so much for the explanation.
    I'm usually either on a room where we have a local internet and we get our internet by cable or I usually use the University Wireless Internet.

    In this case, the Wireless Internet case I found these two values :

    IP 172.19.103.189 and
    Wifi Address : 00:23:12:0e:3e:ac

    I'm guessing it's the first one eh.
    I'll check on my partner PC to check if it's the same as me and if it's different I'll try to work with it in that way!

    Thanks anduril!

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    Yes, the first one (172.19.103.189) is the IP, the other (00:23:12:0e:3e:ac) is the MAC. You need to connect via IP. 172.16.x.x - 172.31.x.x is another group of IPs for private networks.

  9. #9
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by anduril462 View Post
    Yes, the first one (172.19.103.189) is the IP, the other (00:23:12:0e:3e:ac) is the MAC. You need to connect via IP. 172.16.x.x - 172.31.x.x is another group of IPs for private networks.
    Ok, I'll try that later!
    Thanks so much!

  10. #10
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Alright anduril, I've tried it and it works fine, thanks so much!
    I'm gonna keep reading to try to get it working better and I'll post if I have any doubts.

  11. #11
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    K, so now that I got this working I'm trying to broadcast.
    I'm using the IP 255.255.255.255 for that but it's not working.
    You have any idea why ?
    Thanks!

  12. #12
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    You've been here a year, and have 140 posts, and the best explanation of your problem is "it's not working"? Seriously, you have to do better than that if you want help. What error message(s) are you getting? Did you change the code at all? If so, you need to post the new code. Did you read Beej's guide, as your post title might suggest? Specifically, did you read the section on broadcasting? Here's a link to the guide, go do some reading. The answer is probably quite simple.

  13. #13
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Yeah, I've read it and found the answer anduril, thanks so much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem trying to compile beej sample program
    By happyclown in forum Networking/Device Communication
    Replies: 7
    Last Post: 02-28-2009, 02:40 PM
  2. Porting Beej to Windows,
    By m.mixon in forum Networking/Device Communication
    Replies: 1
    Last Post: 06-24-2006, 08:53 PM

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