Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:38:21+00:00 2026-06-11T17:38:21+00:00

I am implementing a raw socket program in python and I came across bind()

  • 0

I am implementing a raw socket program in python and I came across bind() where I can bind my socket to the interface. As I understand it, the first field for this function is the interface I wish to bind to. What is the second field? Is this the Ethertype (such as IP4)? In the raw socket example found in the Python reference docs the code looks like this:

# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))

Why is the second field zero? In other examples I have seen this is frequently set to 0x0800 (or 2048 in decimal) leading me to believe that this is possibly setting the socket to an IP4 protocol. I have also seen this set to 9999. Perhaps I am missing/misunderstanding something here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:38:22+00:00Added an answer on June 11, 2026 at 5:38 pm

    The second field indicates the port number you are binding to. Set it to 0 however, will let the OS pick an available port for you from range 1024 to 65535.

    You can then get the port that was chosen by sock.getsockname()[1].

    Also, setting the first field (host) to 0.0.0.0 or '' will allow accepting connections from any IPv4 address.


    Edit: As @highlycaffeinated pointed out, the above is true because socket.AF_INET address family is chosen. If however, socket.AF_INET6 is chosen, the format will be (host, port, flowinfo, scopeid).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

implementing publishActivity in PHP using the REST API using this code: $activity = array(
When implementing Serializable interface, in Java, we need to set it's serialVersionUID long. Is
when implementing a recursive function during development, i will use a counter and exit
When implementing a hash table using a good hash function (one where the probability
I am implementing a shell-like program where user types command (defined by me). Just
Implementing the very first scala example I ran into some problems probably tipical for
I'm implementing RSACryptoToken, that is an interface for RSA cryptographic tokens, according to the
Implementing Interface just provide the skeleton of the method. If we know the exact
I'm implementing a REST-style interface and would like to be able to create (via
Shouldn't a browser's textarea display raw text? Look at the following snaps from this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.