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

  • SEARCH
  • Home
  • 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 8927117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:08:48+00:00 2026-06-15T08:08:48+00:00

I am trying to implement a bit torrent client. The first step is decode

  • 0

I am trying to implement a bit torrent client.

The first step is decode the torrent file, which I did and here is result:

d8:announce36:http://tracker.mininova.org/announce7:comment41:Auto-generated
torrent by Mininova.org CD13:creation
datei1212041255e4:infod5:filesld6:lengthi291e4:pathl27:Distributed by
Mininova.txteed6:lengthi199784e4:pathl19:the cs
song.mp3.mp3eee4:name33:The Counter Strike Song version 212:piece
lengthi1048576e6:pieces20:趬oîdÏ9`•×=ü¼e6:locale2:en5:title33:The
Counter Strike Song version 2e.

The second step is sending a HTTP GET request to the tracker’s
announce URL with “?” and the following parameters (encoded as above)
appended. This is the part I am struck on. I have been researching how
to send HTTP GET in C; it seem you need first set up a TCP socket and
connect to the tracker server first. I have been doing this:

if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
    printf("fail create socket");
    return 0;
}
char *path = “tracker.mininova.org/announce7”;
struct hostent *hp = gethostbyname(path);
memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
&servAddr.sin_addr.s_addr = ((struct sockaddr_in*)(res->ai_addr))->sin_addr.s_addr;
servAddr.sin_port   = htons(portNum);

However, gethostbyname keep returning null. What am I doing wrong?

  • 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-15T08:08:48+00:00Added an answer on June 15, 2026 at 8:08 am

    You are calling gethostbyname on a string that’s not just a domain, "tracker.mininova.org/announce7". You need to be calling it on just the domain, "tracker.mininova.org". You could check the h_errno value to figure this out.

    However, the use of gethostbyname and related functions should be replaced by use of getaddrinfo anyway (which has the same limitations, but will provide better results).

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

Sidebar

Related Questions

I am trying to implement this bit of code: func factorial(x int) (result int)
I am trying to implement this demo on my local machine. http://bit.ly/4g4o1r I have
First, a bit of context: I'm trying to implement a URL shortening on my
Im trying to implement a GA with tournament selection, but im a bit confused.
I'm trying to re-implement an old Reversi board game I wrote with a bit
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
Trying to implement a search similar to here .This searches properties based on city,locality,property
I am trying to implement recursive deletion of Registry Keys for both 32-bit and
I'm trying to implement an image zoom effect, a bit like how the zoom
I'm trying to implement the simple-linkedinphp library (it's found at http://code.google.com/p/simple-linkedinphp/ ) It runs

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.