Sponsored Content
Operating Systems OS X (Apple) Address family not supported by protocol family Post 302189431 by DNAx86 on Friday 25th of April 2008 06:03:04 PM
Old 04-25-2008
Address family not supported by protocol family

Hi,

I compiled with no error a C program, than I tryed to execute it and than I get this error:

connessione al server fallita: Address family not supported by protocol family


What does it mean?

Why I get this error only on Mac os x while on Ubuntu the program works?

The code is:
/*
* EsameClient.c
*
*/

#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define NR 3
#define MAXLENGTH 80
#define SERVER_PORT 1313

int main (unsigned argc, char **argv)
{
int sockfd;
struct sockaddr_in server={AF_INET,htons(SERVER_PORT),INADDR_ANY};
int i=0,len;
char buf[MAXLENGTH],c;
int buffer[NR], stato;

/* Controllo Parametri Passati da Terminale */
if(argc != 4) // argv[1] -> argv[3] sono le risorse
{
perror("Chiamata corretta del programma:\nnome-programma <risorsa1> <risorsa2> <risorsa3> \n<risorsai> deve essere un intero positivo");
exit(1);
}

/* impostazione del transport end point */
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("chiamata alla system call socket fallita");
exit(1);
}
/* connessione al server */
if(connect(sockfd,(struct sockaddr *)&server,sizeof server)==-1)
{
perror("connessione al server fallita");
exit(2);
}


/* ricezione e stampa a video del messaggio di benvenuto del server */
if(recv(sockfd,buf,27,0)>0)
{
buf[27]='\0';
printf("%s",buf);
}
else
{
perror("Connessione al server interrotta");
exit(3);
}

/* acquisizione della stringa da standard input */
/* while((c=getchar())!='\n' && i<MAXLENGTH)
buf[i++]=c;
buf[i]='\0';
len=strlen(buf); */

// Imposta buffer e len
for(i=0; i<NR;i++)
buffer[i]=argv[i+1];
len=sizeof(buffer); // size?? o # = 3/////////////////////////////////////////////////////


/* invio e ricezione della stringa */
if(send(sockfd,buffer,len,0)==-1) // Se send ritorna -1 = errore
{
perror("Errore nell'invio della richiesta risorse al server");
exit(4);
}
if(recv(sockfd,&stato,len,0)>0)
{
printf("%d\n",stato);
}
else
{
perror("Connessione al server interrotta");
exit(3);
}

/* chiusura della connessione */
close(sockfd);
}
 

7 More Discussions You Might Find Interesting

1. Programming

help me understand exec() family of calls...

how does exec() do it? on successful call of exec() family of functions, they never return... how to i emulate that. assume the standard example, execl("/bin/ls","ls",NULL); now this would never return. i m trying to emulate exec()'s never to return feature... #include<unistd.h>... (4 Replies)
Discussion started by: c_d
4 Replies

2. Solaris

Out of family NDU causing servers to hang

Had to reboot over 30 servers out of 70 or so during out of family code load. Still searching but may all have VxVM 3.5 in common. Our last window had similar outcome but on HPUX. I think it has to do with time outs and volume manager is offlining the devices. This just started happening. Anyone... (0 Replies)
Discussion started by: GaryP
0 Replies

3. UNIX for Dummies Questions & Answers

Family tree illustrated

hello is there a family tree, or words that would illustrate the family tree of, Unix -> Linux As i would understand Unix, it is a OS. And Linux is a ?, is Linux a OS or a sub structure inside of the Unix OS ?. Have you ever seen one of those family tree`s where ma and pa are shown at... (3 Replies)
Discussion started by: cowLips
3 Replies

4. Programming

Working of exec family of functions

Hi, I am studying exec family of functions.Its man page says,it replaces the current process image with a new process image. If it replaces the binary,then after returning back,how does it get the previous parameters of the process which called exec?As replacing process image means replacing all... (1 Reply)
Discussion started by: Radha.Krishna
1 Replies

5. UNIX for Dummies Questions & Answers

Working of exec family of functions

Hi, I am studying exec family of functions.Its man page says,it replaces the current process image with a new process image. If it replaces the binary,then after returning back,how does it get the previous parameters of the process which called exec?As replacing process image means replacing... (5 Replies)
Discussion started by: Radha.Krishna
5 Replies

6. AIX

Determine power family of p system from the model #.

Folks, Again a very silly question :D Could someone tell me, how to determine the power family(540, 520, 575, 595 etc) just by looking into the model # info from prtconf/lsconf o/p of the lpar? I dont want run a search on any search engine to find out the power family or hit IBM website to... (3 Replies)
Discussion started by: thisissouvik
3 Replies

7. Programming

Simple shell running with exec family

# Erroneous question, so can be removed. (0 Replies)
Discussion started by: beginnerboy
0 Replies
SENDMMSG(2)						     Linux Programmer's Manual						       SENDMMSG(2)

NAME
sendmmsg - send multiple messages on a socket SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include <sys/socket.h> int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags); DESCRIPTION
The sendmmsg() system call is an extension of sendmsg(2) that allows the caller to transmit multiple messages on a socket using a single system call. (This has performance benefits for some applications.) The sockfd argument is the file descriptor of the socket on which data is to be transmitted. The msgvec argument is a pointer to an array of mmsghdr structures. The size of this array is specified in vlen. The mmsghdr structure is defined in <sys/socket.h> as: struct mmsghdr { struct msghdr msg_hdr; /* Message header */ unsigned int msg_len; /* Number of bytes transmitted */ }; The msg_hdr field is a msghdr structure, as described in sendmsg(2). The msg_len field is used to return the number of bytes sent from the message in msg_hdr (i.e., the same as the return value from a single sendmsg(2) call). The flags argument contains flags ORed together. The flags are the same as for sendmsg(2). A blocking sendmmsg() call blocks until vlen messages have been sent. A nonblocking call sends as many messages as possible (up to the limit specified by vlen) and returns immediately. On return from sendmmsg(), the msg_len fields of successive elements of msgvec are updated to contain the number of bytes transmitted from the corresponding msg_hdr. The return value of the call indicates the number of elements of msgvec that have been updated. RETURN VALUE
On success, sendmmsg() returns the number of messages sent from msgvec; if this is less than vlen, the caller can retry with a further sendmmsg() call to send the remaining messages. On error, -1 is returned, and errno is set to indicate the error. ERRORS
Errors are as for sendmsg(2). An error is returned only if no datagrams could be sent. VERSIONS
The sendmmsg() system call was added in Linux 3.0. Support in glibc was added in version 2.14. CONFORMING TO
sendmmsg() is Linux-specific. NOTES
The value specified in vlen is capped to UIO_MAXIOV(1024). EXAMPLE
The example below uses sendmmsg() to send onetwo and three in two distinct UDP datagrams using one system call. The contents of the first datagram originates from a pair of buffers. #define _GNU_SOURCE #include <netinet/ip.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> int main(void) { int sockfd; struct sockaddr_in sa; struct mmsghdr msg[2]; struct iovec msg1[2], msg2; int retval; sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { perror("socket()"); exit(EXIT_FAILURE); } sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); sa.sin_port = htons(1234); if (connect(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == -1) { perror("connect()"); exit(EXIT_FAILURE); } memset(msg1, 0, sizeof(msg1)); msg1[0].iov_base = "one"; msg1[0].iov_len = 3; msg1[1].iov_base = "two"; msg1[1].iov_len = 3; memset(&msg2, 0, sizeof(msg2)); msg2.iov_base = "three"; msg2.iov_len = 5; memset(msg, 0, sizeof(msg)); msg[0].msg_hdr.msg_iov = msg1; msg[0].msg_hdr.msg_iovlen = 2; msg[1].msg_hdr.msg_iov = &msg2; msg[1].msg_hdr.msg_iovlen = 1; retval = sendmmsg(sockfd, msg, 2, 0); if (retval == -1) perror("sendmmsg()"); else printf("%d messages sent ", retval); exit(0); } SEE ALSO
recvmmsg(2), sendmsg(2), socket(2), socket(7) Linux 2014-07-08 SENDMMSG(2)
All times are GMT -4. The time now is 01:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy