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 8320589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:42:08+00:00 2026-06-08T22:42:08+00:00

I am writing an application in C# that hooks the connect function call of

  • 0

I am writing an application in C# that hooks the connect function call of another program and reads the IP it is connecting to. (I know it is IPv4)

Currently it hooks, intercepts and forwards the function call and I get the variables but since connect in winsock is called with a sockaddr* variable as the second argument, I need cast this to a sockaddr_in to get the IP address. (Unless there is a way to retrieve the ip out of the sa_data field, which I couldn’t find information about.)

This is where I am stuck. I generated the C# code for the structs using the InteropSignatureToolkit (generated code: http://pastebin.com/twvGw030), but I don’t really see how to cast the sockaddr struct to sockaddr_in. In C++ this would be quite easy, but I don’t know how to do it in C#.

Thanks for taking your time to read this and I hope you can help me. 🙂

  • 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-08T22:42:11+00:00Added an answer on June 8, 2026 at 10:42 pm

    Use an IntPtr in the p/invoke declaration, then you can use Marshal.PtrToStructure. First use sockaddr to find out sa_family, then call Marshal.PtrToStructure again with the more specific type.

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

Sidebar

Related Questions

I'm currently writing an application that displays a lot , and I mean, a
I'm currently writing an application that plays podcasts. I'm representing all the feeds and
I'm writing an application that reads from a MySQL database and migrates data into
I am writing a memory tracking application that hooks all the calls to HeapAlloc
Im writing an application that supposed to send coordinates in an SMS, but I've
I am writing an application that allows a user to place images on a
I am writing an application that will allow an android phone and java application
I am writing an application that sends commands to a unix shell. I am
I'm writing an application that gives the user the option to resize an image
I'm writing an application that will create difficult passwords for the user. The user

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.