Socket programming in C, I don't understand why my code doesn't work

2021.09.27 17:30 SnooChipmunks6 Socket programming in C, I don't understand why my code doesn't work

Hello, could someone help me with my code? I'm stuck.
The exercise (I'm now doing the server part): https://imgur.com/a/UAbbroX The feedback I receive from the automatic correction : https://imgur.com/a/mNHgm1l

My code: 
include
#include  #include  #include  #include  #include  #include  int recv_and_handle_message(const struct sockaddr *src_addr, socklen_t addrlen) { // TODO: Create a IPv6 socket supporting datagrams // TODO: Bind it to the source // TODO: Receive a message through the socket // TODO: Perform the computation // TODO: Send back the result int sock = socket(AF_INET6, SOCK_DGRAM, 0); if(sock == -1) return -1; int err = bind(sock,src_addr,addrlen); if(err == -1) return -1; char buffer [1024]; struct sockaddr_storage peer_addr; socklen_t peer_addr_len = sizeof(struct sockaddr_storage); ssize_t n_received = recvfrom(sock, buffer,1024, 0, (struct sockaddr *)&peer_addr, &peer_addr_len); if(n_received == -1) return -1; if(n_received == 1) { char error = 0; int err3 = sendto(sock, &error, 1, 0, (struct sockaddr *)&peer_addr, peer_addr_len); if(err3 == -1) return -1; } char header = buffer[0]; int flag1 = header; flag1 >>= 5; int result = 0; if(flag1 == 0){ int*begin = (int*)&buffer[1]; for (int i = 0; i < (n_received-1)/4; ++i) { result += ntohl(*(begin)); begin++; } } else if(flag1 == 1){ int*begin = (int*)&buffer[1]; if (((n_received-1)/4) >= 1) result++; for (int i = 0; i < (n_received-1)/4; ++i) { result *= ntohl(*(begin)); begin++; } } else{ char error = 0; int err3 = sendto(sock, &error, 1, 0, (struct sockaddr *)&peer_addr, peer_addr_len); if(err3 == -1) return -1; } int flag2 = header; flag2 = flag2 && 1; if(flag2 == 0){ result = htonl(result); char* message = calloc(1,sizeof(result)+1); int s_code = 1; s_code <<=7; *message = (char)s_code; message++; int*payload = (int*) message; message--; *payload = htonl(result); int err3 = sendto(sock, message, sizeof(int)+1, 0, (struct sockaddr *)&peer_addr, peer_addr_len); if(err3 == -1) return -1; return 0; } else if (flag2 == 1){ char ans[1000]; int len = sprintf(ans,"%d",result); char* message = calloc(1,n_received); int s_code = 1; s_code <<=7; *message = (char)s_code; char* final = message; message++; memcpy(message,ans,n_received-1); int err3 = sendto(sock, final, len+1, 0, (struct sockaddr *)&peer_addr, peer_addr_len); if(err3 == -1) return -1; return 0; } else{ char error = 0; int err3 = sendto(sock, &error, 1, 0, (struct sockaddr *)&peer_addr, peer_addr_len); if(err3 == -1) return -1; } return 0; } 
submitted by SnooChipmunks6 to learnprogramming [link] [comments]


2021.09.27 17:30 Comfortable_Tea7645 Help meeee. I found someone to do this ring… but I need to figure out and finalize what I want so we can start getting it made so I have it in time. What vote do you like? Solitaire or halo? It will be 11x7

Help meeee. I found someone to do this ring… but I need to figure out and finalize what I want so we can start getting it made so I have it in time. What vote do you like? Solitaire or halo? It will be 11x7 submitted by Comfortable_Tea7645 to EngagementRings [link] [comments]


2021.09.27 17:30 Bubblebuttchick Cooking dinner... What do you think of my jeans I'm wearing today???

Cooking dinner... What do you think of my jeans I'm wearing today??? submitted by Bubblebuttchick to GirlsInJeans [link] [comments]


2021.09.27 17:30 The_Snuggliest_Panda This would make home screen widgets so much better:

Add the option to make multiple homescreen “profiles” if you will. And be able to create multiple different home screens with different widgets and icons and save it to your phone to switch through freely. I mean like October is coming up and i wanna make a good ol spooky homescreen but dont wanna put the effort in to change it back after a month
submitted by The_Snuggliest_Panda to iOSsetups [link] [comments]


2021.09.27 17:30 heinaga1989 🟢Shibfinity nft Game Metaverse🟢

⭐⭐⭐⭐⭐ 🟢SHIBFINITY NFT GAME METAVERSE🟢 |Ex-Playstation Devs on team | FREE NFT drops Land and Character Sale for early participants | AMA With Devs on TG 🚀🚀🚀

🏆 UTILITY 🏆

🔥 Shibfinity is a Pokemon-inspired play-to-earn metaverse where anyone can earn tokens while contributing to the ecosystem and playing the game.
🔥 Shibfinity is being developed by a superstar dev team. Some members are Ex Sony Playstation game developers.
🔥 Players and holders of the token can earn rewards
🚨 ANTI-BOT | ANTI-DUMP | ANTI-WHALE - ALL FEATURES INBUILT🚀 🚨
🌟 MARKETING 🌟
🚀 Big budget for PooCoin Ads
🚀 Gaming channels and twitch live streamers campaign
🚀 CMC and CG Fast Track Listing
🚀 Youtube and Twitter Campaigns
🚀Articles and Medium posts
🚀 Reddit promotion
🚀 List on 10 top exchanges within 6 months
💎 TOKENOMICS 💎
5 Billion Total Supply
💎 MARKETING - 15% - PART LOCKED 🔒
💎 PUBLIC SALE - 20%
💎 LIQUIDITY - 10% - LOCKED 🔒
💎 TEAM - 10% - LOCKED 🔒
💎 PLAY TO EARN - 15% - LOCKED 🔒
💎 REWARDS & STAKING - 15% - LOCKED 🔒
💎PRIVATE SALE - 5% - LOCKED 🔒
💎 ECOSYSTEM FUND - 10% LOCKED 🔒
✅ BUY AND SALES TAX ✅
💰 10% Buy Tax
- 4% Fee redistributed to all holders 🚀
- 4% Fee added to liquidity and locked
- 3% Marketing Wallet
💰 25% Sell Tax (for two days after launch to prevent dump)
- 10% Fee redistributed to all holders 🚀
- 5% Fee added to liquidity and locked
- 10% Marketing Wallet
🚀 Join us to get free tokens and a chance to win $1000! 🚀
🌐 Website: https://shibfinity.com
🗣 Telegram: https://t.me/shibfinity
🐦 Twitter: https://twitter.com/Sh1bfinity
👉 $1000 Giveaway - https://sweepwidget.com/view/33638-hvul6om1
submitted by heinaga1989 to thecryptoshots [link] [comments]


2021.09.27 17:30 flanisbae seemingly can't access season of the chosen

TLDR: made a new hunter, get the symbol to access the story at the wartable but cant press square - help would be appreciated :)
finished every piece of content before chosen (maybe bc of crow...) but nothing changed
submitted by flanisbae to destiny2 [link] [comments]


2021.09.27 17:30 NachosConCarne [PC] H: 3*TS Rail Rifle/50c/90rw W: strong melee weapon (prefer it doesn't weight much)

submitted by NachosConCarne to Fallout76Marketplace [link] [comments]


2021.09.27 17:30 ohtobety who’s interested?

submitted by ohtobety to FootTalk [link] [comments]


2021.09.27 17:30 Gyposcvm Dark side and light side

Sorry (kinda) for the amount of questions I ask on this haha. Hopefully nobody noticed!
I had this idea for my campaign where players can gain light side and dark side points on a scale, like in KOTOR or even like the karma in fallout or the honor in red dead redemption lmao.
In a way that only I would see their progress through the dark and light side. Is there an app I can use for this? Or a way to go about this with pencil and paper
submitted by Gyposcvm to sw5e [link] [comments]


2021.09.27 17:30 prawnbiryani 💗☁🍦🌸🧁🤍🦩

submitted by prawnbiryani to 11hr11min [link] [comments]


2021.09.27 17:30 quote_emperor cartolina-aforisma-honore-de-balzac-6

cartolina-aforisma-honore-de-balzac-6 submitted by quote_emperor to aforismiecitazioni [link] [comments]


2021.09.27 17:30 LiteratureOk5964 I read today in the local newspaper that a barber in the city was arrested for drug trafficking

I was his client for a long time but I didn't know he was a barber
submitted by LiteratureOk5964 to Jokes [link] [comments]


2021.09.27 17:30 IcyReveal3238 Chav or love island discord anyone ?

Chav or love island discord anyone ? submitted by IcyReveal3238 to UKInstaGirls [link] [comments]


2021.09.27 17:30 RyanKl (CA-91709) (FS/FT) [H] Underwater Cities, Glenmore 2 Chronicles, Raiders of the North Sea With both Expansions, Kemet [W] Obsession, Rococo Deluxe, Tyrants of the Underdark, Ginkopolis, Inis, Offers

Looking to trade for the following games. Let me know if you have any interest, will also take looks at trades as well.
submitted by RyanKl to BoardGameExchange [link] [comments]


2021.09.27 17:30 WillinWolf 2nd brisket, first time with butchers paper!

2nd brisket, first time with butchers paper! submitted by WillinWolf to smoking [link] [comments]


2021.09.27 17:30 johnrock001 What are Manga and Anime?

What are Manga and Anime? - https://www.myanimeforlife.com/what-are-manga-and-anime/
submitted by johnrock001 to myanimeforlife [link] [comments]


2021.09.27 17:30 DrGalactus PovertyFIRE'd folks who eat mayo - is it worth the hype?

After a couple of f*ck-ups on the part of our local McDonalds, the wife and I are seriously considering buying all our own condiments and damn the extra costs - Mayo being the #1 sauce sachet we can't seem to steal in the U.S..
Just wondering how many here have actually taken the Mayo plunge and what your experiences/feelings have been on the stuff in comparison to other everyday sauces. How is it better, does it live up to its reputation, is it worth the extra travel/fees/time involved, etc.?
Thank you!
submitted by DrGalactus to fijerk [link] [comments]


2021.09.27 17:30 CoinjoyAssistant Cardano (ADA) Partners With Chainlink (LINK) for Oracle Services

Cardano (ADA) Partners With Chainlink (LINK) for Oracle Services submitted by CoinjoyAssistant to CoinJoyIo [link] [comments]


2021.09.27 17:30 Adorable_Admiral Almost didn't spot this mantis thanks to the excellent camouflage

Almost didn't spot this mantis thanks to the excellent camouflage submitted by Adorable_Admiral to whatsthisbug [link] [comments]


2021.09.27 17:30 thedankmemer_1 I’m hoping to get to 1000 followers. If you follow me I’ll follow back!

submitted by thedankmemer_1 to FollowForFollow [link] [comments]


2021.09.27 17:30 Morgan_Molly [H] Office 365 random/custom account [W] Credit Card, PayPal, crypto

SHOP AND DISCORD SERVER LINK: click here
Details about Office 365:
Usual price: $9.99/month
You will get login details of a brand new account that you can log in to office.com and download all Office apps and access OneDrive.
Private account, not shared
Included: * Word * Excel * PowerPoint * 1TB OneDrive Storage * other Office apps
All apps update monthly so you will always have the latest apps on Windows and Mac, unlike Office 2016/2019.
Validity: Lifetime
Delivery: Instant
SHOP AND DISCORD SERVER LINK: click here
submitted by Morgan_Molly to shoppingbay [link] [comments]


2021.09.27 17:30 booboobo2 About to give you a black eye for trying to peek

About to give you a black eye for trying to peek submitted by booboobo2 to AlexaEPerez [link] [comments]


2021.09.27 17:30 altazure Taidetarvikeverkkokauppoja?

Hei /arkisuomi!
Olen tässä korona-aikana alkanut vakavammin harrastaa piirtämistä. Nyt haluaisin hankkia pääkallomallin, joka auttaisi piirtäessä ymmärtämään pään ja kasvojen rakennetta paremmin. Muitakin vastaavia taidetarvikkeita olisi hankintalistalla jossain vaiheessa.
Mistä näitä tällaisia saisi parhaiten hankittua? Kokemuksia suomalaisista/eurooppalaisista taidetarvikeverkkokaupoista?
submitted by altazure to arkisuomi [link] [comments]


2021.09.27 17:30 birdnerd1991 Who's the person you never want to see again?

submitted by birdnerd1991 to AskReddit [link] [comments]


2021.09.27 17:30 MrNicsanic how to mute the FETCH collectron's voice ?

the "voice" option in setting doesn't affect on this thing's voice and it's voice is annoying for me , is there any way to mute it ?
submitted by MrNicsanic to fo76 [link] [comments]


http://moysamara.ru