bind() error


 
Thread Tools Search this Thread
Special Forums IP Networking bind() error
# 1  
Old 05-23-2002
bind() error

Hello. I am havig problems with this program. It is a server supposed to get 2 integers from client, calculate a sum and send result back to client. I am getting a bind() error when attempting to execute it. Any help appreciated

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>

int main (void)
{
  int sd, new_sd, sum;
  struct sockaddr_un serv_addr;

  struct mystruct
  {
    int addend;
    int augend;
  } values;

  void report_fatal_error (char *message);

  sd = socket (AF_UNIX, SOCK_STREAM, 0);

  if (sd == -1)
    report_fatal_error ("Server: Cannot open socket");

  bzero ((char *) &serv_addr, sizeof (serv_addr));

  serv_addr.sun_family = AF_UNIX;

  strcpy (serv_addr.sun_path, "/tmp/mysocket");

  if (bind (sd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) == -1)
    report_fatal_error ("Server: Binding error in local address");

  listen (sd, 5);

  while (1)
  {
    new_sd = accept (sd, NULL, 0);

    if (new_sd == -1)
      report_fatal_error ("Server: Accept error");

    read (new_sd, &values, sizeof (values));

    sum = values.addend + values.augend;

    printf ("server: %d + %d = %d\n", values.addend, values.augend, sum);

    write (new_sd, &sum, sizeof (sum));

    close (new_sd);
  }
}

void report_fatal_error (char *message)
{
  perror (message);

  exit (1);
}

# 2  
Old 06-06-2002
Sorry m8 i am a little rusty on server programming but what port are u telling the server to bind to..??
U must bind it to a well know unreserved port greater than 1024
Sorry of i got this wrong but you would want to set up a portbase to connect to a porrt greater than 1024..
Have a look at comver voulume 3 C/S Programming *Excellent*
That will show u.!!


Mojo
# 3  
Old 06-07-2002
Adding up to Mojo's reply.....

Pls try to print the errno/ err mesage that you get when you bind the socket. That will be more helpful in narrowing down your debugging.

Deepa
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bind

Hi All I need to do bind of exiting filesystem to new storage allocated mount --bind /prod/OpenCSS /var/lib/test echo "/prod/OpenCSS /var/lib/pgsql bind bind 0 0" >> /etc/fstab will this command just work ? (2 Replies)
Discussion started by: anil529
2 Replies

2. Red Hat

Bind (DNS) error on EL 6.4

Gurus I have configured bind 9 on Red hat EL 6.4, it can resolve from hostname i.e from domain name (like cnn.com, bbc.com)but through IP its shows following error. Need your expert opinion to solve it. error 84.23.97.31 Server: 192.168.31.24 Address: 192.168.31.24#53 ** server can't... (1 Reply)
Discussion started by: smazshah
1 Replies

3. UNIX for Dummies Questions & Answers

Can't bind to IP

When you get the message can't bind to ip already in use. is there a command to search to see everything that is using that IP? I've already check the host and hostname files (2 Replies)
Discussion started by: mchelle_99
2 Replies

4. Programming

bind source

here is the bind source file for the client.c in bind9 logs are written in var/log/file name in the form 02-Aug-2012 15:43:12.713 client 192.168.2.4#47512: query: 209.236.125.74.in-addr.arpa IN PTR + (192.168.2.4) i am in a subnet of 10 systems through 192.168.2.1..10 i want to write logs based... (2 Replies)
Discussion started by: balvinder87
2 Replies

5. Solaris

rpc/bind maintanance error

My code Hi Folks, I am getting maintanance error for rpc/bind in one of solaris 10 server.I have tried disable,enabled,cleared all options and dont no how to make online.Please help me Please find the below for details :- Server1> svcs -a rpc/bind svcs: -a ignored when used with... (0 Replies)
Discussion started by: susindram
0 Replies

6. Solaris

bind error

Hi, When I use the ldapadd command I get this error. ldap_simple_bind: Conidentiality required ldap_simple_bind: additional info: confidentiality required I was able to use this command and the ldapsearch command yesterday just fine. I think I may have made a change to a file, but I don't... (2 Replies)
Discussion started by: bitlord
2 Replies

7. Programming

how to solve error : Bind: Address Already in Use

hi i have created socket program with proper IP address and port no client side port no 1085 and 1086 gateway side port no 1086 and 1085 and port no 1087 and 1088 receiver side port no 1088 and 1087 well it works fine on client and gateway side not on receiver and gateway side... (2 Replies)
Discussion started by: bhakti
2 Replies

8. Programming

ldap bind error

hi Using C program i am trying to connect to ldap server i have used the method bind syntax : ldap_bind_s(ld,"cn=Manager,dc=example,dc=com","password") but it is not able to bind and giving error as error 2 :Historical protocol version required use ldapv3 instead do i need to add any... (2 Replies)
Discussion started by: mridula
2 Replies
Login or Register to Ask a Question