This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

socket call failed under g++ option.


I have egcs 1.1.2 installed on my linux 2.2.3 kernel machine.  The
socket call failed if I build my code using g++ instead of gcc.  Here is
the code

//////////////////////////////////////////// test.cc
///////////////////////////////
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>    /* sockaddr_in structure */
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
	//	to get the protocol
	struct protoent *proto;
	int my_socket;
	//	now get the protocol --> This is OK for both g++ and gcc
	if (!(proto = getprotobyname("icmp"))) 
	{
		printf("No ICMP protocol supported\n");
		return -1;
	}

	//	create an ICMP socket ->>    This call failed if using
g++
	my_socket = socket(AF_INET, SOCK_RAW,proto->p_proto); 

	if (my_socket < 0){
		printf("Invalid Socket\n");
	}
	return 0;
}

--Thang


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]