开发者

how can a process execute network code

开发者 https://www.devze.com 2023-01-11 07:17 出处:网络
I am a beginner to networking and I have a few questions regarding networking. 1)How can a process execute code that is sent from a different computer on the network. Generally a process\'s code segm开

I am a beginner to networking and I have a few questions regarding networking. 1)How can a process execute code that is sent from a different computer on the network. Generally a process's code segm开发者_StackOverflow中文版ent cannot be changed once its loaded to ensure protection. (Also I can execute some arbitrary code to corrupt the process's memory) 2)Also can a process hear to multiple ports ? And multiple processes can hear to a same port ? For example two https associated with port 80. How to distinguish between the processes and how to ensure protection ? 3)Also I would like to know how listen is implemented in sockets. Are they implemented as software interrupts ?

Any good book recommendations are very much appreciated.

Thanks & Regards,

Mousey.


Q: How can a process execute code sent from another machine?
A: Generally, this is a bad idea as the security concerns are difficult to fully explore. However, this can be done by saving the network-delivered code to a separate executable and then launching this new program. This can also be done on most systems by just treating the raw bytes received as code; load the bytes into the heap (not the stack!), cast the address to a function pointer, and call it. Again though, this is almost certainly a bad idea.

Q: Can a process listen on multiple ports simultaneously?
A: Yes. By the way, HTTPS is port 443. HTTP is port 80.

Q: Can multiple processes listen on the same port (with the same protocol, on the same address)?
A: No. Other processes might be able to eavesdrop and also receive the packets, but they're not directly bound to the port. In general, only one process can be bound to a given protocol/port/address 3-tuple.

Q: How is blocking while listening on a socket implemented?
A: By the operating system, in its own fashion. Generally a thread is moved into the "blocking" state when it calls accept, read, or poll/select on a non-ready socket, and will not receive CPU time until some data have arrived.


1)How can a process execute code that is sent from a different computer on the network. Generally a process's code segment cannot be changed once its loaded to ensure protection.

This has nothing to do with networking. Once you receive the data through a socket, it's in your local memory. What you do after that is OS-specific. For example, on Windows, you can use VirtualProtect to mark pages as executable.

2)Also can a process hear to multiple ports ?

Sure, just create a different socket for each port you want to listen to. Of course, to use them simultaneously, you either need to use non-blocking sockets or run each socket in a separate thread.

3)Also I would like to know how listen is implemented in sockets. Are they implemented as software interrupts ?

This is entirely OS-specific. listen just sets up the socket so that it can accept connections. Any connection requests that arrive after this (this probably happens somewhere in the TCP/IP driver) are put in a queue by the OS. When you later call accept, the OS pulls out the first pending connection from this queue and returns a socket to that.

0

精彩评论

暂无评论...
验证码 换一张
取 消