How to bind a Raw Socket to a specific port?

前端 未结 2 1040
夕颜
夕颜 2021-02-10 00:22

I am currently working on a programming assignment. The assignment is to implement a client,network emulator, and server. The client passes packets to a network emulator, and th

2条回答
  •  余生分开走
    2021-02-10 01:22

    The man page for raw(7) says:

    A raw socket can be bound to a specific local address using the bind(2) call. If it isn't bound all packets with the specified IP protocol are received. In addition a RAW socket can be bound to a specific network device using SO_BINDTODEVICE; see socket(7).

    Edit: You cannot bind a raw socket to a specific port because "port" is a concept in TCP and UDP, not IP. Look at the header diagrams for those three protocols and it should become obvious: you are working at a lower level, where the concept of port is not known.

提交回复
热议问题