Re: How to send UDP packet from kernel?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Danielle..

I would be interested in that module of yours. Infact, I will soon have to write a module to construct TCP packets from within the kernel and send those packets out on the network to another machine. And I am working with the 2.4.18 kernel too... It will be great if you have a similar module written where you construct TCP packets instead of UDP, but if not, please mail me the module constructing UDP packets..

Thanks in advance,

-Vishwas.

Daniele Bellucci wrote:
On Thu, Dec 11, 2003 at 04:41:15PM +0100, Tomislav Sajdl wrote:
|I would like to send UDP packets directly from kernel. |
|What is the regular way for doing this? Should I manually fill an sk_buff



You can create a socket in kernel space by calling: retval = sock_create(PF_INET, SOCK_DGRAM, 0, &sock);

the bind operations looks like :

	addr_in->sin_family=PF_INET;
	addr_in->sin_port = htons(source_port);
	addr_in->sin_addr.s_addr = source_address;
	memset(&(addr_in->sin_zero), '\0', 8);

	knetlog->addr_in = addr_in;
	retval = sock->ops->bind(sock, (struct sockaddr *) knetlog->addr_in,
				 sizeof(struct sockaddr));

if you want to enable broadcast:
	lock_sock(sock->sk);
	sock->sk->broadcast = 1;
	release_sock(sock->sk);


now, your UDP packet could be sent by:
oldfs = get_fs(); set_fs(KERNEL_DS); /* Required to change addr_limit */
retval = sock_sendmsg(&sock, &msg, len);
set_fs(oldfs);



where msg is an array of char and len is the total number of bytes.



I developed a simple module for 2.4.x where a kernel_thread is created to send UDP packets containing the memory usage. Anyone interested can ask me to send the source code of the kernel module.

(I apologize for my bad english)






-- -- Vishwas Raman Software Engineer, Eternal Systems, Inc, 5290 Overpass Rd, Bldg D, Santa Barbara. CA 93111 Email: vishwas@eternal-systems.com Tel: (805) 696-9051 x246 Fax: (805) 696-9083 URL: http://www.eternal-systems.com/

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux