• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why can't my socket receive any packets?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why can't my socket receive any packets?


  • Subject: Re: Why can't my socket receive any packets?
  • From: Rich Kubota <email@hidden>
  • Date: Wed, 11 Apr 2007 17:40:58 -0700

zheng,

the problem here is that the system registers a protocol handler to process incoing tcp/ip packets before you have a chance to do so. If you are interested in receiving tcp/ip packets, you could implement a bpf filter (which requires root authentication). This reminds me that a bug should be submitted so that if the setsockopt call is made to handle a protocol packets which has already been registered by the system, an error should be returned.

What are you trying to do?? Are you trying to intercept specific tcp/ip traffic??

rich

At 10:06 AM +0800 4/11/07, zheng cheng wrote:
I'm a newbie to OS X, i have search my problem in google, i find someone has the same problem with me, he has posted a mail to this maillist,i just forward his/her mail,


Thanks for your help!

Re: Newbie question about receiving raw ethernet packet

Subject: Re: Newbie question about receiving raw ethernet packet
From: Rich Kubota <<mailto:email@hidden>email@hidden>
Date: Thu, 14 Apr 2005 14:21:10 -0700
Hello Jean,

the BSD sample doesn't really show how to capture Phase 1 Ethernet packets. I tried a quick modification and found the same problem which you describe. I recall that at one times, things worked. Maybe an alternative would be to implement a BPF socket. I'll send a sample to you directly.

rich kubota

At 5:04 PM -0700 4/13/05, Jean Bovet wrote:

Hi,

I'm really new to network programming and I've been reading e-mails from this list as well as the BSDLLCTest example provided by Apple. I'm trying to extract from this example the lines needed to capture raw ethernet packet (I have written a C++ tool that I launch using sudo). Everything works well - no error reported - but I don't receive anything (I'm using another computer to send raw packet to my main machine).

Here is my code:

******

int create_socket(void)
{
	fd = socket(AF_NDRV, SOCK_RAW, 0);
	if(fd < 0) {
		printf("socket() error = %d (%s)\n", errno, get_error(errno));
		return errno;
	}
	return NO_ERR;
}

void create_socket_address(char *name)
{
	saddr.sa_len = sizeof(struct sockaddr);
	saddr.sa_family = AF_NDRV;
    strcpy(saddr.sa_data, name);
}

int bind_socket(void)
{
	int err = bind(fd, &saddr, sizeof(saddr));
	if(err != 0) {
		printf("bind error = %d (%s)\n", err, get_error(err));
		return err;
	}
	return NO_ERR;
}

void set_listening_protocol(void)
{
	struct ndrv_protocol_desc	desc;
    struct ndrv_demux_desc	demux_desc[1];

bzero(&desc, sizeof(desc));			// zero out the strucuture
bzero(&demux_desc, sizeof(demux_desc));		// zero out the strucuture

    desc.version = NDRV_PROTOCOL_DESC_VERS;
    desc.protocol_family = NDRV_DEMUXTYPE_ETHERTYPE;
    desc.demux_count = (u_int32_t)1;
    desc.demux_list = (struct ndrv_demux_desc*)&demux_desc;

	demux_desc[0].type = NDRV_DEMUXTYPE_ETHERTYPE;
	demux_desc[0].length = sizeof(unsigned short);
	demux_desc[0].data.ether_type = htons(0x888e);

int result = setsockopt(fd, SOL_NDRVPROTO, NDRV_SETDMXSPEC, (caddr_t)&desc, sizeof(desc));
if (result != 0)
printf("setsockopt error = %d\n", result);
}


int main (int argc, const char * argv[])
{
	// Create the socket (needs super-user privileges - use 'sudo')
	int err = create_socket();
	if(err != 0)
		return err;

	// Ethernet 0 (built-in)
	create_socket_address("en1");

	// Bind socket
	err = bind_socket();
	if(err != 0)
		return err;

	set_listening_protocol();

	char buffer[2048];
	int addr_len = sizeof(saddr);
	int n = recvfrom(fd, buffer, 2048, 0, &saddr, &addr_len);
//	int n = recvfrom(fd, buffer, 2048, 0, NULL, NULL);
	printf("%d bytes read\n", n);

    return 0;
}

****

I probably put incorrect values in my set_listening_protocol()... any tips ? Also, what happens if I set the two last parameters from the recvfrom() to NULL ?

Thanks for any help!

Jean Bovet

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


-- Sincerely, Rich Kubota email@hidden (408) 974-6212


Best Wishes, CZ



<http://cn.mail.yahoo.com>«¿íçâÎå'ñ…-" îÝ-3.5Góeó ÅC20MïçåèÅI

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


-- Sincerely, Rich Kubota email@hidden (408) 974-6212 _______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Why can't my socket receive any packets? (From: zheng cheng <email@hidden>)

  • Prev by Date: Why can't my socket receive any packets?
  • Next by Date: errSSLBadCipherSuite
  • Previous by thread: Why can't my socket receive any packets?
  • Next by thread: errSSLBadCipherSuite
  • Index(es):
    • Date
    • Thread