Fedora Linux Support Community & Resources Center
Old 1st November 2011, 06:05 PM
giobaxx Offline
Registered User
Join Date: Nov 2011
Posts: 7
network programming and error on socket bind

I'm studying socket programming, and i was trying to do some very simple example
like this
# include <strings.h>
# include <stdlib.h>
# include <netinet/in.h>
# include <stdio.h>
# include <sys/types.h>
# include <sys/socket.h>

int main(int argc, char *argv[]){
    struct sockaddr_in myself, peer;
    int peer_len = sizeof(peer);
    int b_len;

    int s, i;
    char buf[1500];
    if (argc < 2) {
	fprintf (stderr, "Usage: %s port_number\n", argv[0]);
    if ((s=socket(AF_INET, SOCK_DGRAM, 0))==-1) {
      exit (1);

    bzero((char *) &myself, sizeof(myself));
    myself.sin_port= htons(atoi(argv[1]));

    if (bind(s, (struct sockaddr *) &myself, sizeof(myself))==-1) {

       if (recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &peer, &peer_len)==-1){
       printf("Received packet from %s:%d\nData: %s\n\n",
       inet_ntoa(peer.sin_addr), ntohs(peer.sin_port), buf);
When i try to bind a socket with an IP address different by the family 127.0.x.x for example i receive an error "BIND Cannot assign requested address". what i can do?.....tanks
Reply With Quote
Old 2nd November 2011, 12:43 PM
markkuk Offline
Registered User
Join Date: Apr 2005
Location: Finland
Posts: 5,072
Re: network programming and error on socket bind

Use a correct IP address for your machine and the interface you want to use, or INADDR_ANY to bind to all available addresses.
Reply With Quote

bind, error, network, programming, socket

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get link local address of ipv6 using socket programming in c deepa Programming & Packaging 1 11th September 2010 08:51 PM
socket programming in kbasic ?? gowrishankar Using Fedora 0 24th January 2009 06:25 PM
C socket programming Help! qinglau Programming & Packaging 5 3rd May 2006 03:27 PM
socket: bind() error in a udp aplication Owy Programming & Packaging 6 29th March 2006 05:44 PM

Current GMT-time: 20:18 (Friday, 18-08-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat